home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcr / pcr4_4.lha / DIST / gc / GCblack_list.c < prev    next >
C/C++ Source or Header  |  1992-04-16  |  3KB  |  98 lines

  1. /* begincopyright
  2.   Copyright (c) 1991-1992 Xerox Corporation. All rights reserved.
  3.   Use and copying of this software and preparation of derivative works based
  4.   upon this software are permitted. Any distribution of this software or
  5.   derivative works must comply with all applicable United States export
  6.   control laws. This software is made available AS IS, and Xerox Corporation
  7.   makes no warranty about the software, its performance or its conformity to
  8.   any specification. Any person obtaining a copy of this software is requested
  9.   to send their name and post office or electronic mail address to:
  10.     PCR Coordinator
  11.     Xerox PARC
  12.     3333 Coyote Hill Rd.
  13.     Palo Alto, CA 94304
  14.  
  15.   endcopyright */
  16.  
  17. # include <xr/GCPrivate.h>
  18.  
  19. # ifdef BLACK_LIST
  20.  
  21. /*
  22.  * Black list entries contain 2 bits each:
  23.  *  0 ==> not black listed
  24.  *  1 ==> recently black listed
  25.  *  2 ==> about to be removed from black list
  26.  */
  27.  
  28. /* Schedule all pages to be removed from black list.  The next routine     */
  29. /* actually removes those that were not added again in the interim.    */
  30. void GC_prepare_to_clear_black_list()
  31. {
  32.     register long i;
  33.     register long lim =
  34.            (struct hblk *) GC_heaplim - (struct hblk *) GC_heapstart;
  35.     
  36.     for (i = 0; i < lim; i++) {
  37.         GC_blacklist[i] <<= 1;
  38.     }
  39. }
  40.  
  41. void GC_clear_black_list()
  42. {
  43.     register long i;
  44.     register long lim =
  45.            (struct hblk *) GC_heaplim - (struct hblk *) GC_heapstart;
  46.                
  47.     for (i = 0; i < lim; i++) {
  48.         GC_blacklist[i] &= 1;
  49.     }
  50. }
  51.  
  52. /* P is not a valid pointer reference, but it passed quicktest.    */
  53. /* If it is likely to result in a later false reference, than     */
  54. /* add the block it points to the black list.            */
  55. void GC_add_to_black_list(p)
  56. unsigned long p;
  57. {
  58.     register char * GC_heapstart_reg = GC_heapstart;
  59.     register int old_black_list_val;
  60.     register struct hblk * h;
  61. #   define GC_heapstart GC_heapstart_reg
  62.  
  63.     if (p >= (unsigned long) ((struct hblk *) GC_heapstart + MAP_SIZE)) {
  64.         return;
  65.     }
  66.     if ((char *)p < GC_heapstart) {
  67.          GC_abort("GC_add_to_black_list: bad pointer\n");
  68.     }
  69.     h = HBLKPTR(p);
  70.     old_black_list_val = black_list(h);
  71.     if (old_black_list_val != 0) {
  72.       if (old_black_list_val == 2) {
  73.         /* May be interior pointer, but page was previously bad.    */
  74.         black_list(h) = 1;
  75.       }
  76.       return;
  77.     }
  78.     if (get_map(h) != HBLK_INVALID) {
  79.         /* May be a pointer to the interior of a previously allocated */
  80.         /* object.  That's not enough to black list it, unless it was */
  81.         /* previously already black listed.                  */
  82.         return;
  83.     }
  84. #   ifdef PRINTSTATS
  85.     GC_vprintf("Black listing 0x%X (saw 0x%X)\n", h, p);
  86. #   endif
  87.     black_list(h) = 1;
  88. #   undef GC_heapstart
  89. }
  90.  
  91. void GC_rm_from_blacklist(hbp)
  92. struct hblk * hbp;
  93. {
  94.     black_list(hbp) = 0;
  95. }
  96.  
  97. # endif /* BLACK_LIST */
  98.